﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{

    class _ShellReamer222_1
    {
        public static void ShellReamer222_1(Dictionary<string, Object> data)  //套式铰刀
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };    //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //参数
            double soal = Convert.ToDouble(data["oal"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
           /* double soal = 60;
            double scale = 1;*/
            if (scale == 0 && soal < 67)
            {
                scale = 4.0;
            }
            else if (scale == 0 && soal < 90)
            {
                scale = 3.0;
            }
            else if (scale == 0 && soal < 134)
            {
                scale = 2.0;
            }
            else if (scale == 0 && soal < 178)
            {
                scale = 1.5;
            }
            else if (scale == 0 && soal < 268)
            {
                scale = 1.0;
            }
            else if (scale == 0 && soal < 357)
            {
                scale = 0.75;
            }
            else if (scale == 0)
            {
                scale = 0.5;
            }
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);
            

             double dc = Convert.ToDouble(data["dc"]) * scale; //Convert.ToDouble(data["dc"]);
             double apmx = Convert.ToDouble(data["l"]) * scale; //Convert.ToDouble(data["l"]);
             double oal = Convert.ToDouble(data["oal"]) * scale; //Convert.ToDouble(data["oal"]);
             double dmm = Convert.ToDouble(data["dconms"]) * scale; //Convert.ToDouble(data["czcms"]);
             double plgang = Convert.ToDouble(data["plgang"]) * pi / 180; //Convert.ToDouble(data["plgang"]);
             double isframe = Convert.ToDouble(data["isframe"]);
            double c = Convert.ToDouble(data["c"]) * scale;
            /*double dc = 49;
            double apmx = 40;
            double oal = 60;
            double dmm = 23;
            double plgang = 30 * pi / 180;
            double isframe = 0;
            double c = 1.5;*/

            double df = dc - c * 2;
            double plgl = apmx / 8;
            double lf = oal - plgl; //Convert.ToDouble(data["lf"]);
            //坐标
            Vector2 P00 = new Vector2(0, 0);  //vector2 是二维的点
            Vector2 P01 = fun.Polar(P00, 0.5 * pi, oal);  // 基准点 角度（弧度制） 距离      
            Vector2 P5 = fun.Polar(P00, 0, df / 2);
            Vector2 P4 = new Vector2(P00.X + dc / 2, P00.Y + c);
            Vector2 P3 = new Vector2(P4.X, P4.Y + apmx - c);
            Vector2 P1 = new Vector2(P5.X, P5.Y + oal);
            Vector2 P19 = new Vector2(P00.X +dmm/2, P1.Y);
            Vector2 P2 = new Vector2(P5.X, P3.Y + plgl);
            Vector2 P18 = new Vector2(P19.X, P2.Y + 3);
            Vector2 P17 = new Vector2(P18.X - dmm / 10, P18.Y);
            Vector2 P16 = new Vector2(P00.X, P17.Y);
            Vector2 P15 = new Vector2(P00.X - df / 2, P1.Y);
            Vector2 P9 = new Vector2(P00.X - dc / 2, P4.Y);
            Vector2 P12 = new Vector2(P9.X, P00.Y + apmx);
            Vector2 P14 = new Vector2(P15.X, P16.Y);
            Vector2 P13 = new Vector2(P14.X, P14.Y - plgl / 2);
            Vector2 P11 = new Vector2(P12.X + c, P12.Y);
            Vector2 P10 = new Vector2(P9.X + c, P9.Y);
            Vector2 P8 = new Vector2(P9.X + c, P00.Y);
            Vector2 P7 = new Vector2(P8.X + c, P8.Y);
            Vector2 P6 = new Vector2(P17.X - P17.Y / 60, P00.Y);
            Vector2 P31 = new Vector2(P00.X + df / 6, P1.Y);
            Vector2 P32 = new Vector2(P31.X - df / 15, P31.Y - df / 15);
            Vector2 P33 = new Vector2(P32.X, P32.Y - df / 8);
            Vector2 P34 = new Vector2(P33.X - df / 15, P33.Y - df / 15);
            Vector2 P38 = new Vector2(P00.X - df / 6, P1.Y);
            Vector2 P37 = new Vector2(P38.X + df / 15, P32.Y);
            Vector2 P36 = new Vector2(P37.X, P32.Y - df / 8);
            Vector2 P35 = new Vector2(P36.X + df / 15, P36.Y - df / 15);
            Vector2 P50 = new Vector2(P5.X + c/2, P5.Y + apmx / 3);
            Vector2 P55 = new Vector2(P5.X, P50.Y + apmx / 9 - Math.Sqrt(apmx * apmx / 81 - (P50.X - P5.X) * (P50.X - P5.X)));
            Vector2 P51 = new Vector2(P50.X, P50.Y + apmx / 3);
            Vector2 P52 = new Vector2(P55.X, P51.Y - P55.Y + P50.Y);
            Vector2 P53 = new Vector2(P51.X - apmx / 9, P51.Y - apmx / 9);
            Vector2 P54 = new Vector2(P53.X, P50.Y + apmx / 9);
            Vector2 P56 = new Vector2(P5.X - 0.6 * plgl / Math.Tan(plgang), P5.Y);
            Vector2 P59 = new Vector2(P5.X, P5.Y + apmx);
            Vector2 P58 = new Vector2(P59.X - 0.4 * plgl / Math.Tan(plgang), P59.Y);
            Vector2 P57 = new Vector2(P59.X - 0.6 * plgl / Math.Tan(plgang), P59.Y - 0.2 * plgl / Math.Tan(plgang));
            Vector2 a18 = new Vector2(P19.X, P34.Y - (P34.Y - P58.Y) / 2);
            Vector2 a17 = new Vector2(a18.X - dmm / 10, a18.Y);
            Vector2 a16 = new Vector2(P00.X, a17.Y);


            Vector2 p00 = P00;
            Vector2 p01 = fun.rotatePoint_Changed(p00, P01, 90);
            Vector2 p5 = fun.rotatePoint_Changed(p00, P5, 90);
            Vector2 p4 = fun.rotatePoint_Changed(p00, P4, 90);
            Vector2 p3 = fun.rotatePoint_Changed(p00, P3, 90);
            Vector2 p1 = fun.rotatePoint_Changed(p00, P1, 90);
            Vector2 p19 = fun.rotatePoint_Changed(p00, P19, 90);
            Vector2 p2 = fun.rotatePoint_Changed(p00, P2, 90);
            Vector2 p18 = fun.rotatePoint_Changed(p00, P18, 90);
            Vector2 p17 = fun.rotatePoint_Changed(p00, P17, 90);
            Vector2 p16 = fun.rotatePoint_Changed(p00, P16, 90);
            Vector2 p15 = fun.rotatePoint_Changed(p00, P15, 90);
            Vector2 p9 = fun.rotatePoint_Changed(p00, P9, 90);
            Vector2 p12 = fun.rotatePoint_Changed(p00, P12, 90);
            Vector2 p14 = fun.rotatePoint_Changed(p00, P14, 90);
            Vector2 p13 = fun.rotatePoint_Changed(p00, P13, 90);
            Vector2 p11 = fun.rotatePoint_Changed(p00, P11, 90);
            Vector2 p10 = fun.rotatePoint_Changed(p00, P10, 90);
            Vector2 p8 = fun.rotatePoint_Changed(p00, P8, 90);
            Vector2 p7 = fun.rotatePoint_Changed(p00, P7, 90);
            Vector2 p6 = fun.rotatePoint_Changed(p00, P6, 90);
            Vector2 p31 = fun.rotatePoint_Changed(p00, P31, 90);
            Vector2 p32 = fun.rotatePoint_Changed(p00, P32, 90);
            Vector2 p33 = fun.rotatePoint_Changed(p00, P33, 90);
            Vector2 p34 = fun.rotatePoint_Changed(p00, P34, 90);
            Vector2 p38 = fun.rotatePoint_Changed(p00, P38, 90);
            Vector2 p37 = fun.rotatePoint_Changed(p00, P37, 90);
            Vector2 p36 = fun.rotatePoint_Changed(p00, P36, 90);
            Vector2 p35 = fun.rotatePoint_Changed(p00, P35, 90);
            Vector2 p50 = fun.rotatePoint_Changed(p00, P50, 90);
            Vector2 p55 = fun.rotatePoint_Changed(p00, P55, 90);
            Vector2 p51 = fun.rotatePoint_Changed(p00, P51, 90);
            Vector2 p52 = fun.rotatePoint_Changed(p00, P52, 90);
            Vector2 p53 = fun.rotatePoint_Changed(p00, P53, 90);
            Vector2 p54 = fun.rotatePoint_Changed(p00, P54, 90);
            Vector2 p56 = fun.rotatePoint_Changed(p00, P56, 90);
            Vector2 p59 = fun.rotatePoint_Changed(p00, P59, 90);
            Vector2 p58 = fun.rotatePoint_Changed(p00, P58, 90);
            Vector2 p57 = fun.rotatePoint_Changed(p00, P57, 90);
            Vector2 V18 = fun.rotatePoint_Changed(p00, a18, 90);
            Vector2 V17 = fun.rotatePoint_Changed(p00, a17, 90);
            Vector2 V16 = fun.rotatePoint_Changed(p00, a16, 90);


            //
            Vector2 v1 = new Vector2(p00.X + dc / 2, p00.Y);
            Vector2 v2 = new Vector2(v1.X + dc + 8, v1.Y);
            Vector2 v3 = new Vector2(v1.X + dc / 2 + 4, v1.Y);
            Vector2 v4 = new Vector2(v3.X, v3.Y + dc / 2 + 4);
            Vector2 v5 = new Vector2(v3.X, v3.Y - dc / 2 - 4);
            Vector2 v6 = new Vector2(v3.X, v3.Y + dmm / 2);
            Vector2 v7 = new Vector2(v3.X + dmm / 2, v3.Y);
            Vector2 v8 = new Vector2(v3.X, v6.Y * -1);
            Vector2 v11 = new Vector2(v3.X, p1.Y * -1);
            Vector2 v12 = new Vector2(v3.X, p1.Y);
            Vector2 v13 = new Vector2(v3.X + (p1.Y - p00.Y), v3.Y);

            ////
            fun.drawcircle(dxf, v3, dmm / 2, 0.3, contour);
            fun.drawcircle(dxf, v3, (p17.Y - p00.Y), 0.3, contour);
            fun.drawcircle(dxf, v3, (p6.Y - p00.Y), 0.3, contour);
            fun.drawcircle(dxf, v3, (p1.Y - p00.Y), 0.3, contour);
            Arc c1 = fun.DrawArc3(v8, v7, v6);
            Arc c2 = fun.DrawArc3(v11, v13, v12);
            Vector2 v00 = new Vector2(v1.X, p31.Y);
            Vector2 v01 = new Vector2(v2.X, v00.Y);

            Vector2 v9 = fun.getPointForArcandLine(v00, v01, v3, c1);
            Vector2 v10 = fun.getPointForArcandLine(v00, v01, v3, c2);
            Vector2 v14 = new Vector2(v9.X - (p1.Y - dmm / 2) / 12.0658, v9.Y + (p1.Y - dmm / 2) / 12.0658);
            Vector2 v15 = new Vector2(v10.X + (p1.Y - dmm / 2) / 12.0658 * 1.5, v14.Y);
            Vector2 v16 = new Vector2(v3.X - dmm / 2, v3.Y);
            Vector2 v17 = new Vector2(v3.X - (p1.Y - p00.Y), v3.Y);

            Arc c3 = fun.DrawArc3(v6, v16, v8);
            Arc c4 = fun.DrawArc3(v12, v17, v11);
            Vector2 v18 = fun.getPointForArcandLine(v00, v01, v3, c3);
            Vector2 v19= fun.getPointForArcandLine(v00, v01, v3, c4);
            Vector2 v20 = new Vector2(v19.X - (p1.Y - dmm / 2) / 12.0658 * 1.5, v19.Y + (p1.Y - dmm / 2) / 12.0658);
            Vector2 v21 = new Vector2(v18.X + (p1.Y - dmm / 2) / 12.0658, v20.Y);

            Vector2 v22 = new Vector2(v9.X, v9.Y * -1);
            Vector2 v23 = new Vector2(v10.X, v10.Y * -1);
            Vector2 v24 = new Vector2(v15.X, v15.Y * -1);
            Vector2 v25 = new Vector2(v14.X, v14.Y * -1);
            Vector2 v26 = new Vector2(v18.X, v18.Y * -1);
            Vector2 v27 = new Vector2(v19.X, v19.Y * -1);
            Vector2 v28 = new Vector2(v20.X, v20.Y * -1);
            Vector2 v29 = new Vector2(v21.X, v21.Y * -1);
            Vector2 v30 = new Vector2(v3.X, v3.Y + dc / 2);
            Vector2 v31 = fun.Polar(v3, 104 * pi / 180, p1.Y -p00.Y );
            Vector2 v32 = fun.rotatePoint_Changed(v3, v12, 30);
            Vector2 v33 = fun.rotatePoint_Changed(v3, v30, 30);
            Vector2 v34 = fun.rotatePoint_Changed(v3, v31, 30);
            Vector2 v35 = fun.rotatePoint_Changed(v3, v32, 30);
            Vector2 v36 = fun.rotatePoint_Changed(v3, v33, 30);
            Vector2 v37 = fun.rotatePoint_Changed(v3, v34, 30);
            Vector2 v38 = fun.rotatePoint_Changed(v3, v35, 30);
            Vector2 v39 = fun.rotatePoint_Changed(v3, v36, 30);
            Vector2 v40 = fun.rotatePoint_Changed(v3, v37, 30);
            Vector2 v41 = fun.rotatePoint_Changed(v3, v38, 30);
            Vector2 v42 = fun.rotatePoint_Changed(v3, v39, 30);
            Vector2 v43 = fun.rotatePoint_Changed(v3, v40, 30);
            Vector2 v44 = fun.rotatePoint_Changed(v3, v41, 30);
            Vector2 v45 = fun.rotatePoint_Changed(v3, v42, 30);
            Vector2 v46 = fun.rotatePoint_Changed(v3, v43, 30);
            Vector2 v47 = fun.rotatePoint_Changed(v3, v44, 30);
            Vector2 v48 = fun.rotatePoint_Changed(v3, v45, 30);
            Vector2 v49 = fun.rotatePoint_Changed(v3, v46, 30);
            Vector2 v50 = fun.rotatePoint_Changed(v3, v47, 30);
            Vector2 v51 = fun.rotatePoint_Changed(v3, v48, 30);
            Vector2 v52 = fun.rotatePoint_Changed(v3, v49, 30);
            Vector2 v53 = fun.rotatePoint_Changed(v3, v50, 30);
            Vector2 v54 = fun.rotatePoint_Changed(v3, v51, 30);
            Vector2 v55 = fun.rotatePoint_Changed(v3, v52, 30);
            Vector2 v56 = fun.rotatePoint_Changed(v3, v53, 30);
            Vector2 v57 = fun.rotatePoint_Changed(v3, v54, 30);
            Vector2 v58 = fun.rotatePoint_Changed(v3, v55, 30);
            Vector2 v59 = fun.rotatePoint_Changed(v3, v56, 30);
            Vector2 v60 = fun.rotatePoint_Changed(v3, v57, 30);
            Vector2 v61 = fun.rotatePoint_Changed(v3, v58, 30);
            Vector2 v62 = fun.rotatePoint_Changed(v3, v59, 30);
            Vector2 v63 = fun.rotatePoint_Changed(v3, v60, 30);
            Vector2 v64 = fun.rotatePoint_Changed(v3, v61, 30);



      
            //线段
            LwPolyline poly = new LwPolyline();
            poly.Vertexes.Add(new LwPolylineVertex(p1));
            poly.Vertexes.Add(new LwPolylineVertex(p2));
            poly.Vertexes.Add(new LwPolylineVertex(p3));
            poly.Vertexes.Add(new LwPolylineVertex(p4));
            poly.Vertexes.Add(new LwPolylineVertex(p5));
            poly.Vertexes.Add(new LwPolylineVertex(p6));
            poly.Vertexes.Add(new LwPolylineVertex(p7));
            poly.Vertexes.Add(new LwPolylineVertex(p8));
            poly.Vertexes.Add(new LwPolylineVertex(p9));
            poly.Vertexes.Add(new LwPolylineVertex(p12));
            poly.Vertexes.Add(new LwPolylineVertex(p13));
            poly.Vertexes.Add(new LwPolylineVertex(p15));
            poly.Vertexes.Add(new LwPolylineVertex(p38));
            poly.Vertexes[12].Bulge = Math.Tan(pi / (-8));
            poly.Vertexes.Add(new LwPolylineVertex(p37));
            poly.Vertexes.Add(new LwPolylineVertex(p36));
            poly.Vertexes[14].Bulge = Math.Tan(pi / 8);
            poly.Vertexes.Add(new LwPolylineVertex(p35));
            poly.Vertexes.Add(new LwPolylineVertex(p34));
            poly.Vertexes[16].Bulge = Math.Tan(pi / 8);
            poly.Vertexes.Add(new LwPolylineVertex(p33));
            poly.Vertexes.Add(new LwPolylineVertex(p32));
            poly.Vertexes[18].Bulge = Math.Tan(pi / (-8));
            poly.Vertexes.Add(new LwPolylineVertex(p31));
            poly.Vertexes.Add(new LwPolylineVertex(p1));
            fun.PolyFill(dxf, poly, 0.3, contour);
            Vector2[] Line1 = { p1, p52 };
            fun.drawBLine(dxf, Line1, 0.3, contour);
            Vector2[] Line2 = { p53, p54 };
            fun.drawBLine(dxf, Line2, 0.3, contour);
            LwPolyline Arc3 = new LwPolyline();
            Arc3.Vertexes.Add(new LwPolylineVertex(p51));
            Arc3.Vertexes.Add(new LwPolylineVertex(p53));
            Arc3.Vertexes[0].Bulge = (1 - Math.Cos(pi / 4)) * Math.Cos(pi / 4) * 2;
            fun.PolyFill(dxf, Arc3, 0.3, contour);
            LwPolyline Arc4 = new LwPolyline();
            Arc4.Vertexes.Add(new LwPolylineVertex(p54));
            Arc4.Vertexes.Add(new LwPolylineVertex(p50));
            Arc4.Vertexes[0].Bulge = (1 - Math.Cos(pi / 4)) * Math.Cos(pi / 4) * 2;
            fun.PolyFill(dxf, Arc4, 0.3, contour);
            Vector2[] dotline1 = { fun.Polar(p00, 0, 4), fun.Polar(p01, pi, 4) };
            fun.drawPlinetype(dxf, dotline1, 0.15, centre, Linetype.Center);
            Vector2[] xiline1 = { p7, p10, p11, p13, p14 };
            fun.drawPlineOfw(dxf, xiline1, 0.3, contour);
            Vector2[] xiline2 = { p5, p55 };
            fun.drawPlineOfw(dxf, xiline2, 0.3, contour);
            Vector2[] xiline3 = { p2, p1, p19, V18, V17, p6 };
            fun.drawPlineOfw(dxf, xiline3, 0.3, contour);
            Vector2[] xiline4 = { V16, V17 };
            fun.drawPlineOfw(dxf, xiline4, 0.3, contour);

            //
            Vector2[] dotline2 = { v1, v2 };
            fun.drawPlinetype(dxf, dotline2, 0.15, centre, Linetype.Center);
            Vector2[] dotline3 = { v5, v4 };
            fun.drawPlinetype(dxf, dotline3, 0.15, centre, Linetype.Center);
            Vector2[] xiline5 = { v19, v18, v21, v20, v19 };
            fun.drawPlineOfw(dxf, xiline5, 0.3, contour);
            Vector2[] xiline6 = { v9, v10, v15, v14, v9 };
            fun.drawPlineOfw(dxf, xiline6, 0.3, contour);
            Vector2[] xiline7 = { v22, v23, v24, v25, v22 };
            fun.drawPlineOfw(dxf, xiline7, 0.3, contour);
            Vector2[] xiline8 = { v26, v27, v28, v29, v26 };
            fun.drawPlineOfw(dxf, xiline8, 0.3, contour);
            Arc c5 =fun.DrawArc(v21, v3, v14);
            fun.drawBArc(dxf, c5, 0.3, contour);
            Arc c6 = fun.DrawArc(v20, v3, v15);
            fun.drawBArc(dxf, c6, 0.3, contour);
            Arc c7 = fun.DrawArc(v25, v3, v29);
            fun.drawBArc(dxf, c7, 0.3, contour);
            Arc c8 = fun.DrawArc(v24, v3, v28);
            fun.drawBArc(dxf, c8, 0.3, contour);

            LwPolyline LwPolyline1 = new LwPolyline();
            LwPolyline1.Vertexes.Add(new LwPolylineVertex(v12));
            LwPolyline1.Vertexes.Add(new LwPolylineVertex(v30));
            LwPolyline1.Vertexes.Add(new LwPolylineVertex(v31));
            LwPolyline1.Vertexes[1].Bulge = Math.Tan(62 * pi / 180 / 4);
            fun.PolyFill(dxf, LwPolyline1, 0.3, contour);

            LwPolyline LwPolyline2 = new LwPolyline();
            LwPolyline2.Vertexes.Add(new LwPolylineVertex(v32));
            LwPolyline2.Vertexes.Add(new LwPolylineVertex(v33));
            LwPolyline2.Vertexes.Add(new LwPolylineVertex(v34));
            LwPolyline2.Vertexes[1].Bulge = Math.Tan(62 * pi / 180 / 4);
            fun.PolyFill(dxf, LwPolyline2, 0.3, contour);

            LwPolyline LwPolyline3 = new LwPolyline();
            LwPolyline3.Vertexes.Add(new LwPolylineVertex(v35));
            LwPolyline3.Vertexes.Add(new LwPolylineVertex(v36));
            LwPolyline3.Vertexes.Add(new LwPolylineVertex(v37));
            LwPolyline3.Vertexes[1].Bulge = Math.Tan(62 * pi / 180 / 4);
            fun.PolyFill(dxf, LwPolyline3, 0.3, contour);

            LwPolyline LwPolyline4 = new LwPolyline();
            LwPolyline4.Vertexes.Add(new LwPolylineVertex(v38));
            LwPolyline4.Vertexes.Add(new LwPolylineVertex(v39));
            LwPolyline4.Vertexes.Add(new LwPolylineVertex(v40));
            LwPolyline4.Vertexes[1].Bulge = Math.Tan(62 * pi / 180 / 4);
            fun.PolyFill(dxf, LwPolyline4, 0.3, contour);

            LwPolyline LwPolyline5 = new LwPolyline();
            LwPolyline5.Vertexes.Add(new LwPolylineVertex(v41));
            LwPolyline5.Vertexes.Add(new LwPolylineVertex(v42));
            LwPolyline5.Vertexes.Add(new LwPolylineVertex(v43));
            LwPolyline5.Vertexes[1].Bulge = Math.Tan(62 * pi / 180 / 4);
            fun.PolyFill(dxf, LwPolyline5, 0.3, contour);

            LwPolyline LwPolyline6 = new LwPolyline();
            LwPolyline6.Vertexes.Add(new LwPolylineVertex(v44));
            LwPolyline6.Vertexes.Add(new LwPolylineVertex(v45));
            LwPolyline6.Vertexes.Add(new LwPolylineVertex(v46));
            LwPolyline6.Vertexes[1].Bulge = Math.Tan(62 * pi / 180 / 4);
            fun.PolyFill(dxf, LwPolyline6, 0.3, contour);

            LwPolyline LwPolyline7 = new LwPolyline();
            LwPolyline7.Vertexes.Add(new LwPolylineVertex(v47));
            LwPolyline7.Vertexes.Add(new LwPolylineVertex(v48));
            LwPolyline7.Vertexes.Add(new LwPolylineVertex(v49));
            LwPolyline7.Vertexes[1].Bulge = Math.Tan(62 * pi / 180 / 4);
            fun.PolyFill(dxf, LwPolyline7, 0.3, contour);

            LwPolyline LwPolyline8 = new LwPolyline();
            LwPolyline8.Vertexes.Add(new LwPolylineVertex(v50));
            LwPolyline8.Vertexes.Add(new LwPolylineVertex(v51));
            LwPolyline8.Vertexes.Add(new LwPolylineVertex(v52));
            LwPolyline8.Vertexes[1].Bulge = Math.Tan(62 * pi / 180 / 4);
            fun.PolyFill(dxf, LwPolyline8, 0.3, contour);

            LwPolyline LwPolyline9 = new LwPolyline();
            LwPolyline9.Vertexes.Add(new LwPolylineVertex(v53));
            LwPolyline9.Vertexes.Add(new LwPolylineVertex(v54));
            LwPolyline9.Vertexes.Add(new LwPolylineVertex(v55));
            LwPolyline9.Vertexes[1].Bulge = Math.Tan(62 * pi / 180 / 4);
            fun.PolyFill(dxf, LwPolyline9, 0.3, contour);

            LwPolyline LwPolyline10 = new LwPolyline();
            LwPolyline10.Vertexes.Add(new LwPolylineVertex(v56));
            LwPolyline10.Vertexes.Add(new LwPolylineVertex(v57));
            LwPolyline10.Vertexes.Add(new LwPolylineVertex(v58));
            LwPolyline10.Vertexes[1].Bulge = Math.Tan(62 * pi / 180 / 4);
            fun.PolyFill(dxf, LwPolyline10, 0.3, contour);

            LwPolyline LwPolyline11 = new LwPolyline();
            LwPolyline11.Vertexes.Add(new LwPolylineVertex(v59));
            LwPolyline11.Vertexes.Add(new LwPolylineVertex(v60));
            LwPolyline11.Vertexes.Add(new LwPolylineVertex(v61));
            LwPolyline11.Vertexes[1].Bulge = Math.Tan(62 * pi / 180 / 4);
            fun.PolyFill(dxf, LwPolyline11, 0.3, contour);

            LwPolyline LwPolyline12 = new LwPolyline();
            LwPolyline12.Vertexes.Add(new LwPolylineVertex(v62));
            LwPolyline12.Vertexes.Add(new LwPolylineVertex(v63));
            LwPolyline12.Vertexes.Add(new LwPolylineVertex(v64));
            LwPolyline12.Vertexes[1].Bulge = Math.Tan(62 * pi / 180 / 4);
            fun.PolyFill(dxf, LwPolyline12, 0.3, contour);


            //填充1
            LwPolyline poly3 = new LwPolyline();
            poly3.Vertexes.Add(new LwPolylineVertex(p1));
            poly3.Vertexes.Add(new LwPolylineVertex(p2));
            poly3.Vertexes.Add(new LwPolylineVertex(p59));
            poly3.Vertexes.Add(new LwPolylineVertex(p58));
            poly3.Vertexes[3].Bulge = Math.Tan(pi / (8));
            poly3.Vertexes.Add(new LwPolylineVertex(p57));
            poly3.Vertexes.Add(new LwPolylineVertex(p56));
            poly3.Vertexes.Add(new LwPolylineVertex(p6));
            poly3.Vertexes.Add(new LwPolylineVertex(V17));
            poly3.Vertexes.Add(new LwPolylineVertex(V18));
            poly3.Vertexes.Add(new LwPolylineVertex(p19));
            poly3.SetConstantWidth(0.3);
            poly3.IsClosed = true;
            String[] type = new String[100];
            Line[] line = new Line[100];
            Arc[] arc2 = new Arc[100];
            int numst = poly3.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < numst; i++)
            {
                type[i] = poly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (type[i] == "Line")
                {
                    line[i] = (Line)poly3.Explode()[i];
                }
                if (type[i] == "Arc")
                {
                    arc2[i] = (Arc)poly3.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, type, numst, 20, 15, line, arc2, hatching);
            fun.PolyFill(dxf, poly3, 0.3, contour);
            Vector2[] Line3 = { p50, p51 };
            fun.drawBLine(dxf, Line3, 0.3, contour);
            //填充2
            LwPolyline poly4 = new LwPolyline();
            poly4.Vertexes.Add(new LwPolylineVertex(p4));
            poly4.Vertexes.Add(new LwPolylineVertex(p3));
            poly4.Vertexes.Add(new LwPolylineVertex(p2));
            poly4.Vertexes.Add(new LwPolylineVertex(p52));
            poly4.Vertexes[3].Bulge = -Math.Tan(Math.Asin((p51.X - p52.X) * 9 / apmx) / 4);
            poly4.Vertexes.Add(new LwPolylineVertex(p51));
            poly4.Vertexes.Add(new LwPolylineVertex(p50));
            poly4.Vertexes[5].Bulge = -Math.Tan(Math.Asin((p51.X - p52.X) * 9 / apmx) / 4);
            poly4.Vertexes.Add(new LwPolylineVertex(p55));
            poly4.Vertexes.Add(new LwPolylineVertex(p5));
            poly4.SetConstantWidth(0.3);
            poly4.IsClosed = true;
            String[] type3 = new String[100];
            Line[] line3 = new Line[100];
            Arc[] arc3 = new Arc[100];
            int numst1 = poly4.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < numst1; i++)
            {
                type3[i] = poly4.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (type3[i] == "Line")
                {
                    line3[i] = (Line)poly4.Explode()[i];
                }
                if (type3[i] == "Arc")
                {
                    arc3[i] = (Arc)poly4.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, type3, numst1, 20, 12, line3, arc3, hatching);
            fun.PolyFill(dxf, poly4, 0.3, contour);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 3.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 3.5;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            LinearDimension dim1 = new LinearDimension(new Line(p1, p5), offset * 3 + p3.Y - p1.Y, 0, dimensionStyle);
            dim1.UserText = "OAL = " + Math.Round(oal / scale, 2);
            dxf.AddEntity(dim1);
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(p3, p5), offset * 2 + (p3.Y - p5.Y) / 2, 0, dimensionStyle);
            dim2.UserText = "L = " + Math.Round(apmx / scale, 2);
            dxf.AddEntity(dim2);
            //尺寸5
            LinearDimension dim5 = new LinearDimension(new Line(p9, p4), offset, 180+90, dimensionStyle);
            dim5.UserText = "DC = " + Math.Round(dc / scale, 2);
            dxf.AddEntity(dim5);
           
            //图框
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5, 200 + oal / 2));
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

    }
}
